package com.zhouxiaoge.定时器;

import java.util.Calendar;
import java.util.Date;
import java.util.Timer;
import java.util.TimerTask;

/**
 * @author 周明阳
 * mail:gqzmy@outlook.com
 * 时间:2018-03-20 11:06
 */

public class Time {

    public static void timer3() {
        Timer timer = new Timer();
        timer.schedule(new TimerTask() {
            @Override
            public void run() {
                System.out.println("开始执行");
                timer.cancel();
            }
        }, 1000);
    }

    public static void timer2() {
        Timer timer = new Timer();
        timer.schedule(new TimerTask() {
            @Override
            public void run() {
                System.out.println("开始执行");
            }
        }, 1000, 5000);
    }

    public static void timer1() {
        Timer timer = new Timer();
        timer.scheduleAtFixedRate(new TimerTask() {
            @Override
            public void run() {
                System.out.println(">>>>>>>>>>>指定任务<<<<<<<<<<<");
            }
        }, 1000, 2000);
    }

    public static void timer() {
        Calendar calendar = Calendar.getInstance();
        calendar.set(Calendar.HOUR_OF_DAY, 11);
        calendar.set(Calendar.MINUTE, 14);
        calendar.set(Calendar.SECOND, 0);

        Date time = calendar.getTime();
        System.out.println(time);

        Timer timer = new Timer();
        timer.scheduleAtFixedRate(new TimerTask() {
            @Override
            public void run() {
                System.out.println("~~~~~~~~~~~~指定任务~~~~~~~~~~~~");
            }
        }, time, 1000 * 60 * 60 * 24);
    }

}
